
    /**  
    * @Title: TcpChannelHandler.java
    * @Package com.efast.cafe.commponent.es.tcp.handler
    * @Description: TODO(用一句话描述该文件做什么)
    * @author Administrator
    * @date 2019年6月21日
    * @version V1.0  
    */
    
package com.efast.cafe.commponent.es.tcp.channel;

import com.efast.cafe.commponent.es.tcp.coder.ByteToMessageDecoder;
import com.efast.cafe.commponent.es.tcp.handler.TcpProcHandler;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.DelimiterBasedFrameDecoder;
import io.netty.handler.codec.bytes.ByteArrayEncoder;

public class TcpChannelChannel extends ChannelInitializer<SocketChannel>{

	
	    
	@Override
	protected void initChannel(SocketChannel ch) throws Exception {
		ChannelPipeline pipeline =	ch.pipeline();
		ByteBuf delimiter = Unpooled.copiedBuffer("~".getBytes());
		pipeline.addLast(new DelimiterBasedFrameDecoder(1024,delimiter));
		pipeline.addLast(new ByteToMessageDecoder());
		pipeline.addLast(new ByteArrayEncoder());
    	pipeline.addLast(new TcpProcHandler()); 
	}

}
